<template>
  <div v-drag>
    <div class="mask" @click="closePopup(false)"></div>
    <div class="edit_box" v-loading="loading">
      <div class="box_head">
        <p>仓库转单</p>
        <i @click="closePopup(false)"></i>
      </div>
      <div class="box_body">
        <div class="line">
          <span class="lab"><i class="mark_icon">*</i>仓库：</span>
          <div :class="{'error_border':tip_num===1}">
            <el-select
              filterable
              v-model="houseId"
              @change="getWarehouseName"
              placeholder="请选择仓库">
              <el-option
                v-for="(item,index) in houseOption"
                :key="index"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </div>
        </div>
<!--        <div class="line">-->
<!--          <span class="lab">设置目标仓库：</span>-->
<!--          <div>-->
<!--            <el-radio-group v-model="isDefault">-->
<!--              <el-radio :label="1">是</el-radio>-->
<!--              <el-radio :label="0">否</el-radio>-->
<!--            </el-radio-group>-->
<!--          </div>-->
<!--        </div>-->
        <p class="error_line">{{ tipText }}</p>
      </div>
      <div class="box_foot">
        <span @click="closePopup(false)">取消</span>
        <span @click="confirmEdit">确定</span>
      </div>
    </div>
  </div>
</template>

<script>
import {changeOrder} from "@/api/data/user/productReturn";
import {getAllWarehouse} from "@/api/basic/warehouse";

export default {
  props:['changeId','warehouseId'],
  data() {
    return {
      loading: false,
      tipText:'',
      tip_num:'',
      houseOption:[],
      houseId: this.warehouseId ? this.warehouseId : '',
      houseName:'',
      isDefault:1
    }
  },
  mounted() {
    this.getWarehouse();
  },
  methods:{
    getWarehouse(){
      getAllWarehouse('').then((res)=>{
        this.houseOption = res ? res: [];
      })
    },

    getWarehouseName(val){
      let that = this;
      that.tipText='';
      that.tip_num='';
      that.houseOption.forEach((item)=>{
        if (val===item.id){
          that.houseName = item.name;
        }
      })
    },

    confirmEdit() {
      if(this.houseId===''){
        this.tip_num = 1;
        this.tipText = '请选择仓库';
      }else{
        const h = this.$createElement;
        this.$msgbox({
          title: '消息',
          message: h('p', null, [
            h('span', null, '确定将订单 '),
            h('i', {style: 'color: #f7ab20'}, this.recordId),
            h('span', null, '转到「'+this.houseName+'」?'),
          ]),
          showCancelButton: true,
          }).then(() => {
            this.sendInfo();
          }).catch(() => { })
      }
    },

    sendInfo(){
      let that = this;
      let data = {
        returnNo:that.changeId,
        warehouseId:that.houseId,
      }
      changeOrder(data).then(response => {
        that.closePopup(true);
        that.$message.success({
          message:'操作成功！',
          duration:1500
        });
        that.loading = false;
      }).catch((e) => {
        that.loading = false;
      });
    },

    // 关闭
    closePopup(refresh){
      this.$emit('listenToChild',  {refresh:refresh})
    }
  }
}
</script>

<style scoped>

</style>
